Conversation
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/mdx/mdx/5CJ94n8dabCW7aGRbychj2ouQ4G9 |
.eslintrc.yml
Outdated
| import: | ||
| resolver: | ||
| typescript: null | ||
| import/resolver: | ||
| typescript: | ||
| project: packages/*/types |
There was a problem hiding this comment.
So eslint-import-resolver-typescript can find @mdx-js/mdx.Options:
✘ https://google.com/#q=import%2Fnamed
Options not found in '@mdx-js/mdx'
packages/runtime/types/index.d.ts:4:9
2 |
3 | import {FunctionComponent} from 'react'
> 4 | import {Options} from '@mdx-js/mdx'
| ^
5 | import {ComponentsProp} from '@mdx-js/react'
6 |
7 | /**
| "test-api": "jest test", | ||
| "test-coverage": "jest test --coverage", | ||
| "test-api": "NODE_OPTIONS=--experimental-vm-modules jest test", | ||
| "test-coverage": "NODE_OPTIONS=--experimental-vm-modules jest test --coverage", |
There was a problem hiding this comment.
--experimental-vm-modules for tests written in ESM.
| "webpack": "^4.0.0" | ||
| "webpack": "^5.51.1" |
There was a problem hiding this comment.
Upgrade to webpack 5 for webpack/loader-runner#40, although it's still missing webpack/webpack#14077.
| context: __dirname, | ||
| context: fileURLToPath(new URL('.', import.meta.url)), |
There was a problem hiding this comment.
| // Webpack 5: | ||
| // resolve( | ||
| // {source: fs.readFileSync(path.join(__dirname, '..', 'dist', 'main.js'), 'utf8')} | ||
| // ) | ||
| resolve(stats.toJson().modules.find(m => m.name === filePath)) | ||
| resolve({ | ||
| source: fs.readFileSync( | ||
| new URL('../dist/main.js', import.meta.url), | ||
| 'utf8' | ||
| ) | ||
| }) |
There was a problem hiding this comment.
Upgrade to webpack 5 with the help of the existing comments.
|
|
||
| import {Plugin, Compiler, Processor} from 'unified' | ||
|
|
||
| declare namespace mdx { |
There was a problem hiding this comment.
Update types correspondingly.
| bundler.addAssetType('mdx', require.resolve('./MDXAsset.js')) | ||
| import {createRequire} from 'module' | ||
|
|
||
| export default function (bundler) { | ||
| bundler.addAssetType( | ||
| 'mdx', | ||
| createRequire(import.meta.url).resolve('./MDXAsset.js') |
There was a problem hiding this comment.
createRequire() works, until Jest supports import.meta.resolve().
| ], | ||
| "license": "MIT", | ||
| "main": "dist/mdx-react.js", | ||
| "main": "dist/mdx-react.cjs", |
There was a problem hiding this comment.
"type": "module" implies that dist/mdx-react.js is ESM. dist/mdx-react.cjs is identical but explicitly CJS. This avoids:
FAIL test/index.test.js
● Test suite failed to run
SyntaxError: The requested module '@mdx-js/react' does not provide an export named 'MDXProvider'
at Runtime.linkAndEvaluateModule (../../node_modules/jest-runtime/build/index.js:669:5)
at TestScheduler.scheduleTests (../../node_modules/@jest/core/build/TestScheduler.js:333:13)
at runJest (../../node_modules/@jest/core/build/runJest.js:387:19)
at _run10000 (../../node_modules/@jest/core/build/cli/index.js:408:7)
at runCLI (../../node_modules/@jest/core/build/cli/index.js:261:3)
| import {mount} from '@vue/test-utils' | ||
| import remarkSlug from 'remark-slug' | ||
|
|
||
| // See `loader`’s tests for how to upgrade these to webpack 5. |
There was a problem hiding this comment.
Upgrade to webpack 5, same as packages/loader.
|
FYI, current CI failure is pending jestjs/jest#11790. |
|
Thanks @jablko! A related project, XDM, has ESM support https://github.com/wooorm/xdm you may want to check it out. There's been discussion of MDX and XDM merging back together, which would likely bring ESM support into MDX. In the meantime, could you expand a bit on what features/fixes from hast-util-to-estree v2 you are looking for? |
|
Thanks for your work on this Jack. |
|
This is fantastic and exciting, many thanks for your tremendous work! |
I think this is a prerequisite of upgrading to hast-util-to-estree v2? Otherwise I get the following error, because hast-util-to-estree is pure ESM, which
require()doesn't support:To replace
require()withimportI ran the following, plus manual fix-ups:Depends on jestjs/jest#11790
Depends on webpack/webpack#14077